//
//  InstanceFactory.swift
//  Retail
//
//  Created by zhangjikuan on 2020/6/29.
//  Copyright © 2020 aqdeal. All rights reserved.
//

import UIKit

class InstanceFactory: NSObject {
    static let instance = InstanceFactory()
    override init() {
        print("InstanceFactory create")
    }
    
    func createInstanceController(_ className:String) -> AnyObject {
        //1:动态获取命名空间
        guard let spaceName = Bundle.main.infoDictionary!["CFBundleExecutable"] as? String else { return "" as AnyObject }
        let vcClass: AnyClass? = NSClassFromString(spaceName + "." + className)

        // Swift中如果想通过一个Class来创建一个对象, 必须告诉系统这个Class的确切类型
        guard let typeClass = vcClass as? UIViewController.Type else {
            print("vcClass不能当做UIViewController")
            return "" as AnyObject
        }
        let controller = typeClass.init()
        //或者加载xib;   let myVC = typeClass.init(nibName: name, bundle: nil)
        return controller
    }


}
